<template>
  <div id="container" class="clear">
    <div id="login">
      <el-form
        :model="employee"
        status-icon
        :rules="rules2"
        ref="employee"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-form-item label="卡号" prop="num">
          <el-input
            type="text"
            v-model.number="employee.num"
            placeholder="输入卡号或刷卡"
            onkeypress="return( /[\d]/.test(String.fromCharCode(event.keyCode)))"
            auto-complete="off"
          ></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="pwd">
          <el-input
            type="password"
            v-model="employee.pwd"
            placeholder="请输入密码"
            auto-complete="off"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="login('employee')">提交</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    var validateNum = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请输入账号"));
      } else {
        if (this.employee.pwd !== "") {
          this.$refs.employee.validateField("pwd");
        }
        callback();
      }
    };
    var validatePwd = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请输入密码"));
      } else {
        callback();
      }
    };
    return {
      employee: {
        name: "",
        num: "",
        pwd: "",
        quanxian: "",
        id: "",
      },
      rules2: {
        num: [{ validator: validateNum, trigger: "blur" }],
        pwd: [{ validator: validatePwd, trigger: "blur" }],
      },
    };
  },
  methods: {
    login(employee) {
      this.$refs[employee].validate((valid) => {
        if (valid) {
          this.$store.dispatch("loginUser", this.employee);
        } else {
          this.$message("请输入账号密码");
          return false;
        }
      });
    },
  },
  mounted() {}
};
</script>

<style scoped>
#container {
  width: 100%;
  overflow: hidden;
  position: absolute;
  background-image: url("../assets/R-C.png");
  background-repeat: no-repeat;
  background-size: 100% 100%;
}
#login {
  padding: 30px 20px;
  width: 400px;
  border-radius: 5px;
  background-color: #2e527bb3;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  animation-name: example;
  animation-duration: 2s;
}
.el-form{
}
::v-deep .el-form-item  label{
  text-align: center;
  font-size: large;
  color: black;
}
@keyframes example {
  0% {
    opacity: 0.2;
  }
  25% {
    opacity: 0.4;
  }
  50% {
    opacity: 0.6;
  }
  75% {
    opacity: 0.8;
  }
  100% {
    opacity: 1;
  }
}
.el-button {
  width: 100%;
}
</style>